<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ page import="java.util.*"%>
<%@ page import="bean.ConnectMySql,java.sql.*,java.lang.*,bean.selectPrice" %>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>cart</title>
<link rel="stylesheet" href="css/bootstrap.css">
<link rel="stylesheet" href="css/style.css">
<link rel="stylesheet" href="css/font.css">
<script src="js/popper.min.js"></script>
<script src="js/bootstrap.js"></script>
<style>
	.btn-outline-purple {
    color: #9c7157;
    border-color: #9c7157;
  }
  .btn-outline-purple:hover ,
  .btn-outline-purple.active,
  .btn-purple
  {
    color: #fff;
    background-color: #9c7157;
    border-color: #9c7157;
  }
  .btn-purple:hover{
    background-color: #9c7157;
      color: #fff;
      justify-content: right;
  }
  .bg-purple{
    background-color: #9c7157;
  }
  .submit{
  	font-size:20px;
  }
</style>
</head>
<body>
	<%
	response.setCharacterEncoding("UTF-8");
	response.setContentType("text/html;charset=UTF-8");
	String user=(String)session.getAttribute("user");
	String pwd=(String)session.getAttribute("pwd");
	String userId=(String)session.getAttribute("xxx");
	int id=Integer.valueOf(userId);
	PreparedStatement st=null;
	ResultSet rs = null;
	Connection con=ConnectMySql.getConnection();
	request.setCharacterEncoding("UTF-8");
	double total=0;
		try {
  		request.setCharacterEncoding("UTF-8");
	%>
    <!-- 头部开始 -->
    <header>
        <div class="header-content">
            <!-- left start -->
            <div class="logo" style="margin-top:14px;">
                甜甜甜
            </div>
            <!-- left end -->
            <!-- center start -->
            <div class="center">
                <div class="search">
                    <form action="" method="GET" action="">
                        <input type="text" placeholder="TIANPING" name="">
                        <button class="icon-search"></button>
                    </form>
                </div>
                <div class="menu">
                    <ul>
                        <li><a href="login.jsp">首页</a></li>
                        <li><a href="shop.jsp">商品购买</a></li>
                        <li><a href="#">线下活动</a></li>
                        <li><a href="submitPage.jsp">订单</a></li>
                    </ul>
                </div>
            </div>
            <!-- center end -->
            <!-- right start -->
            <div class="right" style="width:200px;">
                <div class="user" style="display:flex;margin:14px auto 0;">
                <%
               		request.setCharacterEncoding("UTF-8");
                	if(pwd!=null && pwd.length()!=0 && user!=null && user.length()!=0){
                %>
                <div style="color:white;font-size:22px;text-align:center;margin-left:100px"><%=user%></div>
                <%
                	}
            	%>
                	
                </div>
                <div class="cart" style="margin-top:20px;">
                    <a href="cart.jsp"><i class="icon-bag" style="background:#735a4f;"></i></a>
                    <div class="price">
                        &yen;
                        <%
                        out.print(selectPrice.select(id));
                        %>
                    </div>
                   <div class="num">
                    <%
                      out.print(selectPrice.num(id));
                    %>
                   </div>
                    <!-- right end -->
                </div>
            </div>
    </header>
	<br />
	
	<div style="width: 1200px;margin:0 auto;">
        <div class="top">
            <div style="margin-top:120px;font-size:20px;font-weight: bold;line-height: 30px;">
                购物车
            </div>
        </div>
     	<div style="margin-top:20px;">
     	<%  
          	st=con.prepareStatement("select * from dish,cart where dish.dishId=cart.dishId and cart.userId=?");
     	    st.setInt(1,Integer.valueOf(userId));
       		rs=st.executeQuery();
         	while(rs.next()){
    	%>
            	<div style="display:flex;justify-content:space-between;align-items: center;border-top:2px solid #9c7157;border-bottom:2px solid #9c7157;margin-bottom:20px;">
                	<img src="<%=rs.getString(6)%>" alt="" style="width:300px;">
                	<div style="font-size:16px;font-weight:bold;"><%=rs.getString(2)%></div>
                	<div style="font-size:20px;">￥<%=rs.getDouble(3)%></div>
                	<div style="display:flex;">
                		<div style="width:100px;display:flex;align-items: center;">
                		  <div>
                		    <form action="subtractNum" method="POST">
                		    <input type="hidden" value="<%=rs.getInt(7)%>" name="cartId"/>
                		    <input type="hidden" value="<%=rs.getInt(10)%>" name="quantity"/>
               	 			<button type="submit" style="border:none;background:white;font-size:18px;margin-right:5px">-</button>
               	 		    </form>
               	 		  </div>
               	 		  <div>
               	 	    	<input  type = "text"  class = "form-control" style="width:35px;" placeholder= "2" value="<%=rs.getInt(10)%>" >
               	 	      </div>
               	 	      <div>
                		    <form action="addNum" method="POST">
                		    <input type="hidden" value="<%=rs.getInt(7)%>" name="cartId"/>
                		    <input type="hidden" value="<%=rs.getInt(10)%>" name="quantity"/>
               	 			<button type="submit" style="border:none;background:white;font-size:18px;margin-right:5px">+</button>
               	 		    </form>
               	 		  </div>
               	 	    </div>
               	 	    <div>
               	 		<form action="deleteCart" method="POST">
                	 		<input type="hidden" name="cartId" value="<%=rs.getInt(7)%>"/>
               			 	<button type="submit" class="btn btn-outline-purple py-1 rounded-pill" >删除</button>
                		</form>
                		</div>
                	</div>
            	</div>
         <%    
        	double t=rs.getDouble(3)*rs.getInt(10);
            total=total+t;
          }
	    %>
        </div>
        <div style="display:flex;justify-content:space-between;">
        	<div style="font-size:20px">总价:</div>
        	<div style="font-size:20px">￥<%=total%></div>
        </div>
        <div style="display:flex;justify-content: right;margin-top:20px;">
        	<a href="shop.jsp"><button type="button" class="btn btn-outline-purple py-1 submit">继续加单</button></a>
        	<a href="submitCart"><button type="button" class="btn btn-outline-purple py-1 submit" style="margin-left:20px;" >提交</button></a>
        </div>
        <%
	      ConnectMySql.closeResultSet(rs);
          ConnectMySql.closeStatement(st);
		  ConnectMySql.closeConnection(con);
		}catch(SQLException e) {
			e.printStackTrace();
		}
	%>
    </div>
    <!-- 底部开始 -->
    <footer>
        <div class="foot" style="border:none;margin-top:60px;">
            <div class="content">
                <dl>
                    <dt>甜甜甜VIP</dt>
                    <dd><a href="#">甜甜甜会员中心</a></dd>
                    <dd><a href="#">常见问题</a></dd>
                </dl>
                <dl>
                    <dt>配送方式</dt>
                    <dd><a href="#">配送时间</a></dd>
                    <dd><a href="#">配送范围</a></dd>
                    <dd><a href="#">配送收费方式</a></dd>
                </dl>
                <dl>
                    <dt>支付方式</dt>
                    <dd><a href="#">微信支付</a></dd>
                    <dd><a href="#">支付宝支付</a></dd>
                    <dd><a href="#">优惠券使用</a></dd>
                    <dd><a href="#">礼品券使用</a></dd>
                </dl>
                <dl>
                    <dt>售后服务</dt>
                    <dd><a href="#">退换货流程及退款</a></dd>
                    <dd><a href="#">订单修改及发票</a></dd>
                    <dd><a href="#">客服联系方式</a></dd>
                    <dd><a href="#">订购说明</a></dd>
                </dl>
            </div>

            <div class="worktime">
                任何问题，联系在线客服。工作时间：周一至周五9:00-21:00：周六，周日：10:00-18:00，法定节假日休息
            </div>
        </div>

    </footer>
    <div class="copyright" style="">
        &copy; copyrights TTT. ALL rights researved 2024.
    </div>
    <!-- 底部结束-->
</body>
</html>